package dhm.com.hpx.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.hpx.R;
import dhm.com.hpx.base.BaseActivity;
import dhm.com.hpx.base.Presenter.PressenterImpl;
import dhm.com.hpx.base.netWork.Constant;
import dhm.com.hpx.base.netWork.LoginContract;
import dhm.com.hpx.entity.Bean;
import dhm.com.hpx.utils.SpUtils;
import dhm.com.hpx.utils.StringUtils;

public class AddrecommendActivity extends BaseActivity implements LoginContract.IView {

    @BindView(R.id.userpwd)
    EditText userpwd;
    @BindView(R.id.newpwd)
    EditText newpwd;
    private String uid;

    private PressenterImpl pressenter;

    @Override
    protected int getLayout() {
        return R.layout.activity_addrecommend;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        uid = SpUtils.getString(this, "uid");
        pressenter=new PressenterImpl();
        pressenter.attachView(this);

    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.back, R.id.sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.sure:
                String feeduser = userpwd.getText().toString();
                String contactInfo = newpwd.getText().toString();

                if (feeduser==null||feeduser.equals("")||contactInfo==null||contactInfo.equals("")){
                    Toast.makeText(this, "请检查数据", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (StringUtils.isRegistMobileNO(contactInfo)) {
                    Toast.makeText(this, "手机号格式错误", Toast.LENGTH_SHORT).show();
                    return;
                }

                Map<String,String> map=new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("uid",uid);
                map.put("feeduser",feeduser);
                map.put("contactInfo",contactInfo);

                pressenter.sendMessage(this,Constant.feedback_add_recommend,map, Bean.class);

                break;
                default:
        }
    }

    @Override
    public void requesta(Object data) {
        if (data instanceof Bean){
            Bean bean= (Bean) data;

            Toast.makeText(this, bean.getMessage(), Toast.LENGTH_SHORT).show();

            if (bean.getCode()==1||bean.getCode()==-3){
                finish();
            }

        }
    }

    @Override
    public void fail(String error) {

    }
}
